//
//  KEAlphabet-onClick.swift
//  KoalaEn
//
//  Created by Wade on 2024/9/10.
//

import Foundation
import UIKit
// https://dict.youdao.com/dictvoice?audio=I%20have%20an%20apple&type=2
extension KEAlphabetNewDetail{
    // 游戏按钮
    @objc func trainingBtnClick(){
        self.pushToGameView()
    }
    // 语言按钮
    @objc func aBtnClick(){
        KEAudioManager.sharedInstance.playEn(en: self.content!, zh: "" )
    }
    // 图片点击
    @objc func wordsImageClick(){
        KEAudioManager.sharedInstance.playEn(en: (self.currentWords?.word_en!)!,zh: "")
    }
    // 单词点击
    @objc func wordsBtnClick(){
        if mLanBtn?.isSelected == true {
            KEAudioManager.sharedInstance.playEn(en: (self.currentWords?.word_en!)!,zh: "")
        }else{
            KEAudioManager.sharedInstance.playEn(en: (self.currentWords?.word_en!)!,zh: (self.currentWords?.word_zh!)!)
        }
    }
    
    @objc func sentensBtnClick(){
        if mLanBtn?.isSelected == true {
            KEAudioManager.sharedInstance.playEn(en: (self.currentWords?.word_sentences?.first!.word_sentences_en)!,zh: "")
        }else{
            KEAudioManager.sharedInstance.playEn(en: (self.currentWords?.word_sentences?.first!.word_sentences_en)!,zh: (self.currentWords?.word_sentences?.first!.word_sentences_zh)!)
        }
    }
    
    @objc func preViewBtnClick(){
        if self.currentIndex == -1 {
            // 提示
            print("已经到第一页了")
        }else{
            self.nextBtn?.isHidden = false
            self.currentIndex -= 1;
            if(self.currentIndex == -1){
                self.preBtn?.isHidden = true
                if(springView2?.isHidden == false){
                    springView2?.alpha = 1
                    springView2?.duration = 0.75
                    springView2?.rotate = 2.0
                    springView2?.animation = "fadeInLeft"
                    springView2?.animateToNext {
                        self.springView2?.isHidden = true
                        self.springView?.isHidden = false
                        self.springView?.alpha = 1
                        self.springView?.duration = 0.75
                        self.springView?.rotate = 2.0
                        self.springView?.animation = "fadeInRight"
                        self.springView?.animateNext(completion: {
                            
                        })
                    }
                }
            }else{
                springView2?.alpha = 1
                springView2?.duration = 0.75
                springView2?.rotate = 2.0
                springView2?.animation = "fadeInLeft"
                springView2?.animateToNext {
                    self.setupWordWithIndex(self.currentIndex)
                    self.springView?.isHidden = true
                    self.springView2?.isHidden = false
                    self.springView2?.alpha = 1
                    self.springView2?.duration = 0.75
                    self.springView2?.rotate = 2.0
                    self.springView2?.animation = "fadeInRight"
                    self.springView2?.animateNext(completion: {
                    })
                }
            }
        }
    }
    @objc func nextBtnClick(){
        guard let menuList = self.menuList else { return }
        if self.currentIndex >= self.menuList!.count - 1 {
            // 提示
            print("已经到最后一页了")
        }else{
            self.nextBtn?.isHidden = false
            self.preBtn?.isHidden = false
            self.currentIndex += 1;
            if(springView?.isHidden == false){
                springView?.alpha = 1
                springView?.duration = 0.75
                springView?.rotate = 2.0
                springView?.animation = "fadeInRight"
                springView?.animateToNext {
                    self.setupWordWithIndex(self.currentIndex)
                    self.springView?.isHidden = true
                    self.springView2?.isHidden = false
                    self.springView2?.alpha = 1
                    self.springView2?.duration = 0.75
                    self.springView2?.rotate = 2.0
                    self.springView2?.animation = "fadeInLeft"
                    self.springView2?.animateNext(completion: {
                    })
                }
            }else{
                springView2?.alpha = 1
                springView2?.duration = 0.75
                springView2?.rotate = 2.0
                springView2?.animation = "fadeInRight"
                springView2?.animateToNext {
                    self.setupWordWithIndex(self.currentIndex)
                    self.springView?.isHidden = true
                    self.springView2?.isHidden = false
                    self.springView2?.alpha = 1
                    self.springView2?.duration = 0.75
                    self.springView2?.rotate = 2.0
                    self.springView2?.animation = "fadeInLeft"
                    self.springView2?.animateNext(completion: {
                    })
                }
            }
        }
        
    }
    
    @objc func lanBtnClick(sender:UIButton){
        sender.isSelected = !sender.isSelected
        self.setupWordWithIndex(self.currentIndex)
    }
    @objc func recordBtnClick(){
        
    }
    @objc func startGameBtnClick(){
        
    }
    
}
